export default {
  data() {
    return {
      goodList: [],
      totalNum: 0,
      goodNum: 0,
      totalPrice: 0,
      shareContent: "",
      shareTit: "",
      shareUrl: "",
      shareImg: "",
      isMiniprogram: false,
      another_pay_url: "",
      styleTwo:false,
      code_url:''
    };
  },

  watch: {
    shareContent: function(newVal, oldVal) {
      console.log(newVal, oldVal);
      if (newVal == oldVal) {
        return;
      } else {
        if (this.fun.isTextEmpty(newVal)) {
          return;
        } else {
          this.another_pay_url = newVal + "：" + this.shareUrl;
          this.fun.wxShare(
            "",
            {},
            {
              title: this.shareTit,
              imgUrl: this.shareImg,
              description: newVal,
              link: this.shareUrl
            },
            data => {}
          );
        }
      }
    }
  },
  methods: {
    //获取订单详情
    getOrderDetail() {
      $http
        .get("order.another-pay-detail", {
          order_id: this.$route.params.order_id,
          pid: window.localStorage.getItem("uid")
        })
        .then(response => {
          if (response.result === 1) {
            this.getShareInfo();
            this.goodList = response.data;

            let numSum = 0;

            response.data.forEach(val => {
              return (numSum += val.goods_total);
            });

            this.totalNum = numSum;
            this.getPrice();
          } else {
            this.$dialog.alert({ message: response.msg });

            this.$router.go(-1);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    shareTip() {
      this.$dialog.alert({ message: "请点击右上角分享！" });
    },
    shareByApp(){
      let json = {
        title: this.shareTit,
        imgUrl: this.shareImg,
        description: this.shareContent,
        link: this.shareUrl
      };

      if (this.fun.isCPS()) {
        if (this.fun.isIosOrAndroid() === "ios") {
          shareByH5IOS({ body: "shareByH5IOS", json: JSON.stringify(json) });
        } else {
          shareByH5Android(JSON.stringify(json));
        }
      } else {
        YDB.Share(json.title, json.desc, json.imgUrl, json.link, "Sharesback");
      }
    },
    onCopy() {
      this.$toast({
        message: "复制成功",
        duration: 3000
      });
    },

    miniPay() {
      window.location.href = this.shareUrl;
    },

    //获取默认分享数据
    getShareInfo() {
      if (window.isMiniprogram) {
        this.isMiniprogram = true;
      }
      $http
        .get("member.member.anotherShare", {
          order_ids: this.$route.params.order_id
        })
        .then(response => {
          if (response.result === 1) {
            this.shareTit = response.data.title;
            this.shareUrl = response.data.url;
            this.shareImg = response.data.img;
            this.shareContent = response.data.content;
            if(response.data.code_url){
              this.code_url = response.data.code_url;
            }
            this.another_pay_url = this.shareContent + "：" + this.shareUrl;
            this.fun.wxShare(
              "",
              {},
              {
                title: this.shareTit,
                imgUrl: this.shareImg,
                description: this.shareContent,
                link: this.shareUrl
              },
              data => {}
            );
            try {
              window.history.replaceState('', '', this.shareUrl);//修改当前的链接，解决cps app 左上角的原生分享，链接为当前页面链接不是代付链接
            } catch (error) {
              console.log(error);
            }
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    init() {
      this.goodList = [];
      this.totalNum = 0;
      this.totalPrice = 0;
      this.goodNum = 0;
      this.shareContent = "";
      this.shareTit = "";
      this.shareUrl = "";
      this.shareImg = "";
    },

    //获取实付价格
    getPrice() {
      $http
        .get("order.merge-pay.anotherPayOrder", {
          order_ids: this.$route.params.order_id,
          pid: window.localStorage.getItem("uid")
        })
        .then(response => {
          if (response.result === 1) {
            this.totalPrice = response.data.order_pay.amount;
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  },
  activated() {
    this.init();
    // if(this.$route.params.order_id.indexOf(',')){
    //     console.log("有逗号");
    // }else{
    //     console.log("无逗号");

    // }
    console.log(this.$route.params)
    if(this.$route.params.style){
      this.styleTwo = true;
    }
    this.getOrderDetail();
  },
  components: { }
};
